﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using QuanLyBanHang.DataConnection;
using System.Windows.Forms;
using System.Data;

namespace QuanLyBanHang.QuerySQL
{
    class ClassNCC
    {
        Connect conn = new Connect();
        public DataTable ShowNCC(int i,string ma = null, string ten = null)
        {
            DataTable tb = new DataTable();
            switch (i)
            {
                case 0:
                    {
                        try
                        {
                            string sql = "select *from NHACC";
                            tb = conn.getTable(sql);
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show("Lỗi: " + e.Message);
                        }
                        break;
                    }
                case 1:
                    {
                        try
                        {
                            string sql = "select *from NHACC where MANCC like '%" + ma + "%'";
                            tb = conn.getTable(sql);
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show("Lỗi: " + e.Message);
                        }
                        break;
                    }
                case 2: {
                    try
                    {
                        string sql = "select *from NHACC where TENNCC like N'%" + ten + "%'";
                        tb = conn.getTable(sql);
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show("Lỗi: " + e.Message);
                    }

                    break;
                }
            }
            return tb;
        }
        //
        public void ThemNCC(string ma, string ten, string sdt, string diachi)
        {
            try
            {
                string sql = "insert into NHACC values('" + ma + "',N'" + ten + "','" + sdt + "',N'" + diachi + "')";
                conn.ExcuteQuerySql(sql);
                MessageBox.Show("Thêm thành công !!!");
            }
            catch (Exception e)
            {
                MessageBox.Show("Lỗi: " + e.Message);
            }
        }
        //
        public void SuaNCC(string mansx, string tennsx, string sdt, string diachi)
        {
            try
            {
                string sql = "update NHACC set TENNCC = N'" + tennsx + "', SODTNCC = '" + sdt + "', DIACHINCC =N'" + diachi + "' where MANCC = '" + mansx + "' ";
                conn.ExcuteQuerySql(sql);
                MessageBox.Show("Sửa thành công !!!");
            }
            catch (Exception e)
            {
                MessageBox.Show("Lỗi: " + e.Message);
            }
        }
        //
        public void XoaNCC(string ma)
        {
            try
            {
                string sql = "delete NHACC where MANCC = '" + ma + "'";
                conn.ExcuteQuerySql(sql);
                MessageBox.Show("Xóa thành công !!!");
            }
            catch (Exception e)
            {
                MessageBox.Show("Lỗi: " + e.Message);
            }
        }
    }
}
